<?php
/**
 * 意见反馈表
 * @author a
 *
 */
class Feedback extends CT_Controller{
    
    private $offse = 0;
    private $page_size = 0;
    private $page = 0;
    private $size = 10; //每页显示数量
    private $substr_num = 10;   //列表显示留言数量
    
    function __construct()
    {
        parent::__construct();
        $this->load->helper("arraytool");   //加载工具
        $this->load->helper("tools_helper");   //加载工具
        $this->t = $this->ct_template;
        
        $this->load->model('feedback_model');
        $this->load->model('member_model');
        
        //分页
        $this->page = $this->input->get('per_page',TRUE) ? intval($this->input->get('per_page',TRUE)) : 1;
        $this->page_size = $this->config->item('per_page')?$this->config->item('per_page'):$this->size;
        $this->offse = ($this->page-1) * $this->page_size;
        
    }
    
    /**
     * 列表
     */
    public function Index(){
        try {
            //$fild = 'id as order_id,course_package_id,hours,surplus_hours,status';
            //$where = "nursery_id = '$this->_nursery_id'";
            $feedback_list = $this->feedback_model->findAll(array('status'=>1),'*','id desc',$this->offse,$this->page_size);
            if(empty($feedback_list))throw new Exception('没有记录');
            
            $total = $this->feedback_model->findCount(array()); //总数
            $pagelink = $this->pagination($total,$this->page_size);
            
            //获取用户名
            $where = "id IN (". filterValue($feedback_list,'member_id',true) .")";
            $member_list = $this->member_model->findAll($where,'id,baby_name,linkman');
            $member_list = restByKey($member_list,'id');
            
            $feedback_list = arrayMerge($feedback_list,'member_id',$member_list);
                        
            //echo '<pre>';print_r($book_list);die();
            $this->t->write_view('content', 'admin/feedback/index', array(
                'pagelink'     =>  $pagelink,
                'feedback_list'    =>  $feedback_list,
            		'substr_num'   =>   $this->substr_num,
            ), false);
            
            $this->t->render();
            
        }catch (Exception $e){
            $error = $e->getMessage();
            $this->t->write_view('content', 'nursery/msg_error', array(
                'error'     =>  $error,
                'time'  =>  10,
                //'url'   =>  '/admin/book/',
            ), false);
            $this->t->render();
        }
        
    }
    /**
     * 修改状态
     */
    public function update(){
    	try {
    		$id = intval($this->input->get('id'));
    		if(empty($id))throw new Exception('评论ID为空');
    		$where['id'] = $id;
    		$bool = $this->feedback_model->update(array('status'=>0),$where);
    		if(empty($bool))throw new Exception('修改失败');
    
    		redirect("/admin/feedback");
    	}catch (Exception $e){
    		die($e->getMessage());
    	}
    }
    /**
     * 详情
     * @throws Exception
     */
    public function info(){
    	try {
    		$id = intval($this->input->get('id'));
    		if(empty($id))throw new Exception('ID为空');
    		$feedback_info = $this->feedback_model->find(array('id'=>$id));
    		if(empty($feedback_info))throw new Exception('没有记录');
    
    		//获取用户名
    		$where = "id = '{$feedback_info['member_id']}'";
    		$member_list = $this->member_model->find($where);
    		
    	}catch (Exception $e){
    		$error = $e->getMessage();
    	}
    	$this->t->write_view('content', 'admin/feedback/info', array(
    			'feedback_info' =>  $feedback_info,
    			'member_list'  =>  $member_list,
    			'error'     =>  empty($error) ? '' : $error,
    	), false);
    	$this->t->render();
    }
}






























